package com.javasm.adminapi.module.aftersalesbase.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.javasm.adminapi.module.aftersalesbase.entity.B2cReturnMsg;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (B2cReturnMsg)表数据库访问层
 *
 * @author makejava
 * @since 2025-10-17 15:21:24
 */
public interface B2cReturnMsgDao extends BaseMapper<B2cReturnMsg> {

    @Select("select \n" +
            "  msg.*,\n" +
            "\tom_order.*,\n" +
            "\tt_spu.*,\n" +
            "\tts.spu_no as ts_spu_no,\n" +
            "\tts.spu_name as ts_spu_name,\n" +
            "\tts.spu_model as ts_spu_model,\n" +
            "\tts.brand_id as ts_brand_id,\n" +
            "\tts.spu_color as ts_spu_color,\n" +
            "\tts.spu_money as ts_spu_money,\n" +
            "\tts.`status` as ts_status\n" +
            "from b2c_return_msg msg\n" +
            "LEFT JOIN om_order on msg_order_code = oo_order_code\n" +
            "LEFT JOIN om_order_goods on oog_order_code = oo_order_code\n" +
            "LEFT JOIN t_spu on spu_no = oog_goods_code\n" +
            "LEFT JOIN t_spu ts on ts.spu_no = msg_tspu_code " +
            "where msg.msg_id = #{msgId} ")
    @Results({
            // 嵌套订单实体
            @Result(column = "oo_id", property = "omOrder.ooId"),
            @Result(column = "oo_order_code", property = "omOrder.ooOrderCode"),
            @Result(column = "oo_order_time", property = "omOrder.ooOrderTime"),
            @Result(column = "oo_order_type", property = "omOrder.ooOrderType"),
            @Result(column = "oo_order_action", property = "omOrder.ooOrderAction"),
            @Result(column = "oo_bussiness_type", property = "omOrder.ooBussinessType"),
            @Result(column = "oo_order_state", property = "omOrder.ooOrderState"),
            @Result(column = "oo_cnee_name", property = "omOrder.ooCneeName"),
            @Result(column = "oo_cnee_account", property = "omOrder.ooCneeAccount"),
            @Result(column = "oo_cnee_phone", property = "omOrder.ooCneePhone"),
            @Result(column = "oo_cnee_cellphone", property = "omOrder.ooCneeCellphone"),
            @Result(column = "oo_cnee_postal_code", property = "omOrder.ooCneePostalCode"),
            @Result(column = "oo_cnee_address", property = "omOrder.ooCneeAddress"),
            @Result(column = "oo_cnee_deli_way", property = "omOrder.ooCneeDeliWay"),
            @Result(column = "oo_cnee_deli_fare", property = "omOrder.ooCneeDeliFare"),
            @Result(column = "oo_cnee_deli_method", property = "omOrder.ooCneeDeliMethod"),
            @Result(column = "oo_cnee_email", property = "omOrder.ooCneeEmail"),
            @Result(column = "oo_remark", property = "omOrder.ooRemark"),
            @Result(column = "oo_update_time", property = "omOrder.ooUpdateTime"),
            @Result(column = "oo_pro", property = "omOrder.ooPro"),
            @Result(column = "oo_city", property = "omOrder.ooCity"),
//
//            // 嵌套商品实体
            @Result(column = "spu_no", property = "tSpu.spuNo"),
            @Result(column = "spu_name", property = "tSpu.spuName"),
            @Result(column = "spu_money", property = "tSpu.spuMoney"),
            @Result(column = "status", property = "tSpu.status"),
            @Result(column = "spu_color", property = "tSpu.spuColor"),
            @Result(column = "spu_model", property = "tSpu.spuModel"),

            //退换商品实体
            @Result(column = "ts_spu_no", property = "tsSpu.spuNo"),
            @Result(column = "ts_spu_name", property = "tsSpu.spuName"),
            @Result(column = "ts_spu_money", property = "tsSpu.spuMoney"),
            @Result(column = "ts_status", property = "tsSpu.status"),
            @Result(column = "ts_spu_color", property = "tsSpu.spuColor"),
            @Result(column = "ts_spu_model", property = "tsSpu.spuModel"),
    })
    B2cReturnMsg selectWithUserName(Integer msgId);



    @Select("select * from b2c_return_msg msg\n" +
            "LEFT JOIN om_order oo on msg_order_code = oo_order_code\n" +
            "LEFT JOIN om_order_goods on oog_order_code = oo_order_code\n" +
            "LEFT JOIN t_spu on spu_no = oog_goods_code\n" +
            "WHERE msg_id = #{id} ")
    B2cReturnMsg selectUnionById(Integer id);
}

